package de.schule.barnimgymnasium.javafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.TilePane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Widgets extends Application {

    public static void main(final String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(final Stage primaryStage) throws Exception {
        final TilePane pane = new TilePane();
        pane.prefColumnsProperty().setValue(2);
        // Text
        pane.getChildren().add(new Text("Text"));
        final Text text = new Text("Einfacher Text");
        text.setFont(Font.font("Arial", 60));
        text.setEffect(new DropShadow(2, 3, 3, Color.RED));
        pane.getChildren().add(text);
        // Canvas
        pane.getChildren().add(new Text("Canvas"));
        final Canvas canvas = new Canvas();
        // TODO: canvas.getGraphicsContext2D()...
        pane.getChildren().add(canvas);
        // BarChart
        pane.getChildren().add(new Text("BarChart"));
        final BarChart<String, Number> bc = this.createBarChart();
        pane.getChildren().add(bc);
        // TreeView
        pane.getChildren().add(new Text("TreeView"));
        final TreeView<String> tv = this.createTreeView();
        pane.getChildren().add(tv);
        // get this party started ...
        final ScrollPane scroll = new ScrollPane();
        scroll.setContent(pane);
        primaryStage.setScene(new Scene(scroll));
        primaryStage.show();
    }

    private BarChart<String, Number> createBarChart() {
        final String austria = "Austria";
        final String brazil = "Brazil";
        final String france = "France";
        final String italy = "Italy";
        final String usa = "USA";
        final CategoryAxis xAxis = new CategoryAxis();
        final NumberAxis yAxis = new NumberAxis();
        final BarChart<String, Number> bc = new BarChart<String, Number>(xAxis, yAxis);
        bc.setTitle("Country Summary");
        xAxis.setLabel("Country");
        yAxis.setLabel("Value");

        final XYChart.Series<String, Number> series1 = new XYChart.Series<String, Number>();
        series1.setName("2003");
        series1.getData().add(new XYChart.Data<String, Number>(austria, 25601.34));
        series1.getData().add(new XYChart.Data<String, Number>(brazil, 20148.82));
        series1.getData().add(new XYChart.Data<String, Number>(france, 10000));
        series1.getData().add(new XYChart.Data<String, Number>(italy, 35407.15));
        series1.getData().add(new XYChart.Data<String, Number>(usa, 12000));

        final XYChart.Series<String, Number> series2 = new XYChart.Series<String, Number>();
        series2.setName("2004");
        series2.getData().add(new XYChart.Data<String, Number>(austria, 57401.85));
        series2.getData().add(new XYChart.Data<String, Number>(brazil, 41941.19));
        series2.getData().add(new XYChart.Data<String, Number>(france, 45263.37));
        series2.getData().add(new XYChart.Data<String, Number>(italy, 117320.16));
        series2.getData().add(new XYChart.Data<String, Number>(usa, 14845.27));

        final XYChart.Series<String, Number> series3 = new XYChart.Series<String, Number>();
        series3.setName("2005");
        series3.getData().add(new XYChart.Data<String, Number>(austria, 45000.65));
        series3.getData().add(new XYChart.Data<String, Number>(brazil, 44835.76));
        series3.getData().add(new XYChart.Data<String, Number>(france, 18722.18));
        series3.getData().add(new XYChart.Data<String, Number>(italy, 17557.31));
        series3.getData().add(new XYChart.Data<String, Number>(usa, 92633.68));
        return bc;
    }

    private TreeView<String> createTreeView() {
        final TreeItem<String> spitzwinkligesDreieck = new TreeItem<String>("spitzwinkliges Dreieck");
        final TreeItem<String> rechtwinkligesDreieck = new TreeItem<String>("rechtwinkliges Dreieck");
        final TreeItem<String> stumpfwinkligesDreieck = new TreeItem<String>("stumpfwinkliges Dreieck");
        final TreeItem<String> gleichschenkligesDreieck = new TreeItem<String>("gleichschenkliges Dreieck");
        final TreeItem<String> gleichseitigesDreieck = new TreeItem<String>("gleichseitiges Dreieck");
        final TreeItem<String> dreiecke = new TreeItem<String>("Dreiecke");
        dreiecke.getChildren().addAll(spitzwinkligesDreieck, rechtwinkligesDreieck, stumpfwinkligesDreieck);
        final TreeItem<String> drachenviereck = new TreeItem<String>("Drachenviereck");
        final TreeItem<String> rhombus = new TreeItem<String>("Rhombus");
        final TreeItem<String> trapez = new TreeItem<String>("Trapez");
        final TreeItem<String> parallelogramm = new TreeItem<String>("Parallelogramm");
        final TreeItem<String> rechteck = new TreeItem<String>("Rechteck");
        final TreeItem<String> quadrat = new TreeItem<String>("Quadrat");
        final TreeItem<String> vierecke = new TreeItem<String>("Vierecke");
        vierecke.getChildren().addAll(drachenviereck, rhombus, parallelogramm, quadrat);
        final TreeItem<String> polygone = new TreeItem<String>("Polygone");
        final TreeItem<String> root = new TreeItem<String>("Ebene Flächen");
        root.setExpanded(true);
        root.getChildren().addAll(dreiecke, vierecke, polygone);
        final TreeView<String> treeView = new TreeView<String>(root);
        return treeView;
    }

}
